-
Notifications
You must be signed in to change notification settings - Fork 920
Remote property accessor on branch branch should not throw an exception #823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
LibGit2Sharp.Tests/BranchFixture.cs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is a bit funny... it returns GitError.Ambiguous instead of GitError.NotFound, but I don't think it is actually ambiguous. Neither 53fc32d or 0266163 can be resolved to a commit, but different error codes are returned for these two cases (53fc32d resolves to a tree, 0266163 resolves to a blob).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ambiguous is indeed an odd error to return. I would expect this to return some form of invalid, since you can't make a branch point to a blob.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error is coming when LibGit2Sharp attempts to peel the object (via git_object_peel(...)) to a commit. git_object_peel is returning different error codes.
I agree that LibGit2Sharp also has room to be more helpful. Currently, it is just saying that it could not find a commit for the given spec (which, is not wrong). It could be improved to be more specific and indicate that the given spec refers to an object of an invalid type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's what I would expect from such an API. "not found" leads me to believe that I gave it something which doesn't exist, when the case is that I gave it something which exists, but is of the wrong type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding repo.CreateBranch(name, "refs/tags/point_to_blob") and repo.CreateBranch(name, "53fc32d"), how about throwing InvalidSpecificationException instead by giving a more detailed message (Something like "Provided target cannot be resolved to a commit")?
ea8f740 to
0b7bd7f
Compare
|
@nulltoken - I tweaked this PR so that |
bbbdc00 to
e16864e
Compare
|
@nulltoken - I was looking at why |
If we think there is value in the caller knowing they passed in a spec that matches some object, but not the expected type (and I think there is), then option 2 seems like the way to go. The downside would be yet another exception that callers of this method would have to know about and handle. The main problem I was trying to solve with this PR is to not have the property accessor throw an exception, so I feel like this is a bit of feature creep - but I can try and see how much work this turns out to be. |
35dc1a4 to
fcbe836
Compare
|
@nulltoken OK - the latest proposal is to move entry point for getting the remote of a remote-tracking branch into it's own function. My thinking is that this is a more complicated operation with greater potential for failure and so it deserves it's own function. This restores the Thoughts? |
fcbe836 to
d4b2fb7
Compare
|
I'm not sure exposing a property and a method that both seems to perform the same thing would be very user friendly. How about starting by
If that doesn't turn to be good enough from a user perspective, we may eventually promote this property into a method and make it throw explicit exceptions. |
d4b2fb7 to
49d24be
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You've just been VS'ed 😉
49d24be to
85be650
Compare
The Branch.Remote property can throw when it attempts to resolve a remote for a remote-tracking branch, and the remote cannot be found or is ambiguous. In those situations, Branch.Remote should return null. If there is a need for the specific exception to be returned, we can look at transitioning to a method for this functionality.
85be650 to
0e5bfbc
Compare
|
👍 for me. |
|
🚀 |
When a branch is under the refs/remotes/ namespace, but a specific remote cannot be resolved,
then the Remote property accessor should return null instead of throwing an exception.